<template>
  <div class="home">
    <el-container>
      <el-header>
        <div class="home_header_container">
          <div class="home_header_logo_container">
            <div class="home_header_logo">
              <img src="../assets/logo.png"/>
            </div>
            <div>电商后台管理系统</div>
          </div>
          <div>
            <el-button type="info" round
            @click="onClickOut">退出登录</el-button>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="160px">
          <el-menu background-color="rgb(51, 54, 66)"
          text-color="#fff"
          :default-openeds="defaultOpen"
          :default-active="'0-0'"
          @select="onClickSelect">
            <el-submenu v-for="(item,index) in menus"
            :key="index"
            :index="String(index)">
              <template slot="title"><i :class="item.icon"></i>{{item.menuName}}</template>
              <el-menu-item v-for="(subItem,subIndex) in item.subMenus"
              :key="subIndex"
              :index="`${index}-${subIndex}`">{{subItem.subMenuName}}</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <div>
            <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// @ is an alias to /src


export default {
  name: 'Home',
  components: {
    
  },
  data(){
    return{
      menus:[],
      defaultOpen:['0']
    }
  },
  methods:{
    onClickOut(){
      window.localStorage.removeItem("token");
      this.$router.push("/login");
    },
    onClickSelect(index,indexPath){
      console.log(index,indexPath);
      var path = ""
      switch (index){
        case "0-0":
          path = "/";
          break;
        case "1-0":
          path = "/member";
          break;
        case "1-1":
          path = "/jurisdiction"
          break;
        default:
          path = "/"
          break
      }
      this.$router.push(path);
    }
  },
  //生命周期
  mounted(){
    this.$axios.get("http://localhost:8080/menu.json").then((res)=>{
      this.menus = res.data;
    })
  }
}
</script>


<style>
 .el-header, .el-footer {
    background-color:rgb(54, 60, 65);
    /* color: #333; */
    height: 60px;
  }
  
  .el-aside {
    background-color:rgb(51, 54, 66);
    color: #333;
    text-align: center;
    height: 90vh;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  .home_header_container
  {
    width: 100%;
    height: 100%;
    display: inline-flex;
    justify-content: space-between;
    align-items: center;
  }

  .home_header_logo_container
  {
    height: 100%;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 30px;
    font-weight: 700;
  }

  .home_header_logo
  {
    display: inline-flex;
    justify-content: center;
    align-items: center;
  }

  .home_header_logo_container img
  {
    width: 50px;
  }
</style>
